package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.collect.CollectUserActiveReq;
import com.qumitech.visualnovel.controller.vo.game.GameCollectReq;
import com.qumitech.visualnovel.service.collect.CollectService;
import com.qumitech.visualnovel.service.oldgame.OldGameService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author :  ZhChNing
 * @Descriptiom :
 * @Date Created in 2019/5/29 12:08
 */

@RestController
@RequestMapping(value = "/api/collect")
public class CollectController {
    @Autowired
    CollectService collectService;
    @Autowired
    OldGameService gameService;

    @PostMapping("/user/active")
    public BaseRsp getCollectUserActiveInfo(@RequestBody CollectUserActiveReq collectUserActiveReq) {

        if (collectUserActiveReq.getOffset() == null) {
            collectUserActiveReq.setOffset(0);
            collectUserActiveReq.setLimit(20);
        }

        return new BaseRsp(ResultEnum.SUCCESS, collectService.getCollectUserActiveInfo(collectUserActiveReq));

    }

    @GetMapping("/wechatalarm/list")
    public BaseRsp getWeChatAlarmInfo(@RequestParam(value = "offset", defaultValue = "0") Integer offset,
                                      @RequestParam(value = "limit", defaultValue = "20") Integer limit,
                                      @RequestParam(value = "startTime", required = false) String startTime,
                                      @RequestParam(value = "endTime", required = false) String endTime) {
        return new BaseRsp(ResultEnum.SUCCESS, collectService.getWeChatAlarmInfo(offset, limit, startTime, endTime));


    }

    @PostMapping("/game")
    public BaseRsp getGameCollectInfo(@RequestBody GameCollectReq gameCollectReq) {

        if (gameCollectReq.getOffset() == null) {
            gameCollectReq.setOffset(0);
            gameCollectReq.setLimit(20);
        }


        return new BaseRsp(ResultEnum.SUCCESS, gameService.getGameCollectVoList(gameCollectReq));
    }

    @PostMapping("/game/unload")
    public BaseRsp UpLoadGameCollectInfo(@RequestBody GameCollectReq gameCollectReq, HttpServletResponse request) {
        gameService.exportMultipartFile(gameCollectReq, request);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PostMapping("/user/active/unload")
    public BaseRsp UpLoadUserActiveInfo(@RequestBody CollectUserActiveReq collectUserActiveReq, HttpServletResponse request) {
        collectService.exportMultipartFile(collectUserActiveReq, request);
        return new BaseRsp(ResultEnum.SUCCESS);
    }
}
